<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'mcfour.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->



<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/hplus/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/hplus/css/plugins/sweetalert/sweetalert.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/hplus/js/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/hplus/js/bootstrap.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/hplus/js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>



<link rel="stylesheet" href="css/mcone.css" type="text/css">
<script type="text/javascript" src="js/jquery.form.js"></script>

<script type="text/javascript">
	var cai = 0;
	function GetQueryString(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
		var r = window.location.search.substr(1).match(reg);
		if (r != null) return (r[2]);
		return null;
	}

	var sname = GetQueryString("spid");
	if (sname != null) {
		var sname_ = decodeURIComponent(sname);
		cai = sname;
	}


	function save() {
		var name = $("#name").val();

		var current = $("#current").val();

		var money = $("#money").val();

		$.post("mcfour.do?pan=jia", {
			"name" : name,
			"current" : current,
			"money" : money,
			"spid" : cai
		}, function(date) {
			var stu = eval("(" + date + ")");
			$("#dg").bootstrapTable("load", stu);
			$("#myModal").modal('hide');
		})
	}
	
	function uploadPic() {  
		console.log("1");
		var  name = $("#name").val();
	
		var current = $("#file").val();
        // 上传设置  
        var options = {  
                // 规定把请求发送到那个URL  
                url: "mcfour.do?pan=jia",  
                // 请求方式  
                type: "post",  
                data:{"name":name,"money":money,"spid":cai},
                // 服务器响应的数据类型  
                dataType: "json",  
                // 请求成功时执行的回调函数  
                success: function(data, status, xhr) {  
                    // 图片显示地址  
                   //var stu = eval("(" + date + ")");
					//$("#dg").bootstrapTable("load", stu);
					//$("#myModal").modal('hide');
                }  
        };  
          console.log("2");
        $("#jvForm").ajaxSubmit(options);  
        console.log("3");
    }  
	
	

	function del1() {
		var arr = $("#dg").bootstrapTable('getAllSelections');
		if (arr.length == 0) {
			swal({
				title : "你未选中任何一行！",
				text : "1秒后自动关闭。",
				timer : 1500,
				showConfirmButton : false
			});
		} else {

			swal({
				title : "确定删除吗？",
				text : "你将无法恢复该虚拟文件！",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "确定删除！",
				cancelButtonText : "取消删除！",
				closeOnConfirm : false,
				closeOnCancel : false
			},
				function(isConfirm) {
					if (isConfirm) {
					
					$.each(arr,function(i,e){
					console.log($(e).parent());
						$.post("mcfour.do?pan=del", {
								"id" : e.id,
								"spid" : cai
							}, function(date) {
								
								$("#myModal").modal('hide');
								
								$(e).remove();
							});
					});


						swal("删除！", "你的虚拟文件已经被删除。",
							"success");
					} else {
						swal("取消！", "你的虚拟文件是安全的:)",
							"error");
					}
				});
		}

	}



	$(function() {
		$("#dg").bootstrapTable({
			url : "mcfour.do?pan=quan&spid=" + cai,
			striped : true,
			pagination : true,
			sidePagination : 'server',
			pageSize : 10,
			pageNumber : 1,
			pageList : [ 10, 20, 30 ],
			search : true,
			clickToSelect : true,
			//singleSelect:true,
			height : 630,
			toolbar : '#d1',
			columns : [ {
				checkbox : true
			},
				{
					field : 'id',
					title : 'id'
				},
				{
					field : 'name',
					title : '名称'
				},
				{
					field : 'img',
					title : '图片',
				},
				{
					field : 'money',
					title : '价格',
				}
			]
		})
	})
</script>

</head>

<body>


	<div class="div">
		<table id="dg"></table>
		<div id="d1" class="d1">
			<button type="button" class="btn" data-toggle="modal"
				data-target="#myModal">增加</button>

			<button onclick="del1()" type="button" class="btn btn-danger">
				<span class="glyphicon glyphicon-trash"></span>&nbsp;删除
			</button>



			<button onclick="toedit1()" type="button" class="btn btn-default">
				<span class="glyphicon glyphicon-pencil"></span> 编辑
			</button>
		</div>


		<!-- Modal -->
		<div class="modal fade" id="myModal">
			<div class="modal-dialog" style="width:600,height:303px;"
				role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title" id="myModalLabel">增加材料</h4>
					</div>
					<div class="modal-body">
						<!-- form开始 -->
						<form  id="jvForm" action="" method="post" enctype="multipart/form-data">
							<div class="form-group">
								<label for="name" style="float: left;">材料名称:</label> <input
									type="text" class="form-control" id="name"
									placeholder="请输入材料名称">
							</div>

							<div class="form-group">
								<label for="file" style="float: left;">图片地址:</label> 
								<input id="file" type="file" name="file" class="form-control">
							</div>
							<div class="form-group">
								<label for="money" style="float: left;">价格:</label> <input
									type="text" class="form-control" id="money"
									placeholder="请输入材料价格">
							</div>
						</form>

					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button onclick="uploadPic()" type="button" class="btn btn-primary"  data-dismiss="modal">提交</button>
					</div>
				</div>
			</div>
		</div>
</body>
</html>
